package com.sanrenzu.chunbo.ui.fenlei.xiangqing;

import android.os.Handler;
import android.os.Looper;

import com.sanrenzu.chunbo.bean.zxb.ShouYeDianJiBean;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by My on 2016/9/1.
 */
public class XiangQingPersenter implements XiangQingContract.Persenter {

    private XiangQingContract.View view;
    private XiangQingContract.Modle modle;

    public XiangQingPersenter(XiangQingContract.View view){
        this.view=view;
        modle= new XiangQingModle();
    }

    @Override
    //表明我要做的事（网络数据访问），然后通过modle获取网络数据， 通过view确定我是否展现成功，展现了json数据
    //图文详情
    public void getVerticalShouYeBean() {
        modle.onGetVerticalShouYeDianJi(new Callback<ShouYeDianJiBean>() {
            @Override
            public void onResponse(Call<ShouYeDianJiBean> call, Response<ShouYeDianJiBean> response) {
                final ShouYeDianJiBean bean = response.body();
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetVerticalShouYeDianJiBean(bean);
                    }
                });
            }
            @Override
            public void onFailure(Call<ShouYeDianJiBean> call, Throwable t) {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetVerticalFailed("首页点击网络访问失败");
                    }
                });
            }
        });
    }
}
